package com.woniuxy.yuekeuser.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.yuekeuser.controller.Form.HotolCarForm;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.yuekeuser.model.Hotolcar;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import com.woniuxy.yuekeuser.model.HotolcarImage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Freedom
 * @since 2020-11-03
 */
public interface HotolcarMapper extends BaseMapper<Hotolcar> {
    @Select("<script>" +
            "SELECT\n" +
            "hotolcar.hotolcar_id,\n" +
            "hotolcar.hotolcar_people_number,\n" +
            "hotolcar.hotolcar_location,\n" +
            "hotolcar.campsite_id,\n" +
            "hotolcar.hotolcar_number,\n" +
            "hotolcar.hotolcar_state,\n" +
            "hotolcar.hotolcar_price,\n" +
            "hotolcar.hotolcar_name,\n" +
            "hotolcar.hotolcar_heat\n" +
            "FROM\n" +
            "hotolcar" +
            " <where>" +
            "campsite_id = #{campsiteId}" +
            "<if test='hotolPeopleNum!=0'>" +
            " and hotolcar_people_number = #{hotolPeopleNum} " +
            " </if>" +
            " </where>" +
            "<if test='choose==1'>" +
            " order by hotolcar.hotolcar_price desc " +
            " </if>" +
            "<if test='choose==2'>" +
            " order by hotolcar.hotolcar_price" +
            " </if>" +
            "<if test='choose==3'>" +
            " order by hotolcar.hotolcar_heat desc" +
            " </if>" +
            "<if test='choose==4'>" +
            " order by hotolcar.hotolcar_heat" +
            " </if>" +
            "<if test='choose==5'>" +
            " order by hotolcar.hotolcar_number desc" +
            " </if>" +
            "<if test='choose==6'>" +
            " order by hotolcar.hotolcar_number " +
            " </if>" +
            " </script>" +
            "")
    public IPage<HotolCarForm> findAllHotolcar(Page<HotolCarForm> hotolcarPage,int hotolPeopleNum,int choose,int campsiteId);

//    public IPage<HotolCarForm> findAllHotolcar(Page<HotolCarForm> hotolcarPage,@Param("hotolPeopleNum") int hotolPeopleNum,@Param("choose") int choose,@Param("campsiteId") int campsiteId);

    @Select("SELECT\n" +
            "hotolcar.hotolcar_id,\n" +
            "hotolcar.hotolcar_people_number,\n" +
            "hotolcar.hotolcar_location,\n" +
            "hotolcar.campsite_id,\n" +
            "hotolcar.hotolcar_number,\n" +
            "hotolcar.hotolcar_state,\n" +
            "hotolcar.hotolcar_price,\n" +
            "hotolcar.hotolcar_name,\n" +
            "hotolcar.hotolcar_heat,\n" +
            "hotolcar.hotolcar_words\n" +
            "FROM\n" +
            "hotolcar\n" +
            "WHERE\n" +
            "hotolcar.hotolcar_id = #{hotolcarId}")
    public Hotolcar queryHotolCarById(int hotolcarId);

    @Update("UPDATE hotolcar\n" +
            " set hotolcar_heat = #{hotolcarHeat}\n" +
            "WHERE\n" +
            "hotolcar_id = #{hotolcarId} ")
    public void addHotolcarHeat(int hotolcarHeat,int hotolcarId);
    /**
     * 酒店房车表新增数据
     * @param hotolcar
     */
    @Insert("insert into hotolcar (hotolcar_people_number,campsite_id,hotolcar_number,hotolcar_price,hotolcar_name,hotolcar_words) values(#{hotolcarPeopleNumber},#{campsiteId},#{hotolcarNumber},#{hotolcarPrice},#{hotolcarName},#{hotolcarWords})")
    @Options(useGeneratedKeys = true,keyProperty = "hotolcarId")
    public void addHotelCar(Hotolcar hotolcar);

    /**
     * 根据名字查询酒店房车的id
     */
    @Select("select hotolcar_id from hotolcar where hotolcar_name = #{hotoCarName} ")
    public int findHotoCarIdByHotoCarName(String hotoCarName);

    /**
     * 动态查询酒店房车
     */
    public List<Hotolcar> findHotocars(String campsiteName,int index ,int size );

    /**
     * 通过酒店房车id查询图片
     */
    @Select("Select hotolcar_id,hotolcar_image_address,hotolcar_image_words from hotolcar_image where hotolcar_id = #{id}")
    public List<HotolcarImage> findcarImageByCarId(int id);

    /**
     * 动态查询酒店房车数据条数
     */
    public int findHotolcarCount(String campsiteName);


}
